package com.crazy.email;

import javax.mail.internet.MimeMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;

@Service
public class EmailService {

	@Autowired
	private JavaMailSender javaMailSender;
	
	/**
	 * 发送富文本邮件（内嵌html标签）
	 */
	public void sendMime() throws Exception {
		MimeMessage message = javaMailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
        // 收件人邮箱
        helper.setTo("");
        // 正文内容
        helper.setText("邮件正文内容", true);
        // 发件人邮箱
        message.setFrom("");
        // 邮件标题
        message.setSubject("邮件标题");
        javaMailSender.send(message);
	}
	
	/**
	 *  发送纯文本邮件
	 */
	public void sendSimple() throws Exception {
		SimpleMailMessage message = new SimpleMailMessage();
		message.setTo("");
		message.setText("");
        javaMailSender.send(message);
	}
	
}
